package Coffee.dao;

import Coffee.bean.Order;
import Coffee.util.Cbase;

import java.util.List;

public class OrderDaoImpl extends Cbase implements OrderDao {

    @Override
    public int insertOrder(String orderid,String userid, String username, String cofid, String cofname, int cofcount, int coftotal, String createtime) {
        String sql = "insert into tb_order (orderid,userid,username,cofid,cofname,cofcount,coftotal,createtime) values (?,?,?,?,?,?,?,?)";
        return update(sql,orderid,userid,username,cofid,cofname,cofcount,coftotal,createtime);
    }

    @Override
    public List<Order> queryOrder(String username) {
        String sql = "select * from tb_order where username = ?";
        return getAll(Order.class,sql,username);

    }

    @Override
    public List<Order> queryOrderAll() {
        String sql = "select * from tb_order";
        return getAll(Order.class,sql);
    }

    @Override
    public List<Order> queryOrderByState(String username, String orderstate) {
        String sql = "select * from tb_order where username = ? and orderstate = ?";
        return getAll(Order.class,sql,username,orderstate);
    }

    @Override
    public int updateOrderState(String orderstate, String orderid) {
        String sql = "update tb_order set orderstate = ? where orderid =?";
        return update(sql, orderstate, orderid);
    }

    @Override
    public Order queryOrderByOrderId(String orderid) {
        String sql = "select * from tb_order where orderid = ?";
        return getOne(Order.class,sql,orderid);
    }

    @Override
    public List<Order> queryOrderAdmin(String username) {
        String sql = "SELECT * FROM `tb_order`WHERE `username` = ? AND `orderstate` NOT IN ('已完成', '已取消')";
       return getAll(Order.class,sql,username);
    }
}
